package com.hotel.controllers;

import com.hotel.entitys.Reserve;
import com.hotel.entitys.RestPOJO;
import com.hotel.services.ReserveService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author chend
 * @time 2022/03/02 11:28:46
 */
@RestController
@Api(tags="客户预定接口")//tags:说明信息
public class ReserveController {
    @Autowired
    private ReserveService reserveService ;

    @ApiOperation(
            value = "客户预定信息增加",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )

    @PostMapping("/addRese")
    public RestPOJO addRese(@RequestBody Reserve reserve){
         Integer  i = reserveService.addRese(reserve);
        RestPOJO restPOJO = new RestPOJO();
        if (i>0){
            restPOJO.setMessage("增加成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("增加失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }

    @ApiOperation(
            value = "删除客户预定信息",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/delById")
    public RestPOJO delById(Integer reserve_id){
        Integer i = reserveService.delById(reserve_id);
        RestPOJO restPOJO = new RestPOJO();
        if (i>0){
            restPOJO.setMessage("删除成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("删除失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }

    @ApiOperation(
            value = "查询客户预定信息通过房号",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/selByCode")
    public RestPOJO selByCode(Integer room_code){
        Reserve reserve = reserveService.selByCode(room_code);
        RestPOJO restPOJO = new RestPOJO();
        if(reserve!=null){
            restPOJO.setMessage("查询成功");
            restPOJO.setStatus(1000);
            restPOJO.setData(reserve);
        }else {
            restPOJO.setMessage("查询失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO;
    }
    @ApiOperation(
            value = "预定转入住，改变预定表status列状态，1：预定，2：入住",
            httpMethod = "GET",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @GetMapping("/setRestatus")
    public RestPOJO setReStatus(String room_code){
          Integer i = reserveService.setReStatus(room_code);
        RestPOJO restPOJO = new RestPOJO();
        if (i>0){
            restPOJO.setMessage("修改成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("修改失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }
    @ApiOperation(
            value = "修改预定信息",
            httpMethod = "POST",
            protocols = "HTTP",
            produces = "application/json",
            response = RestPOJO.class
    )
    @PostMapping("/setReserve")
    public RestPOJO setReserve(@RequestBody Reserve reserve){
        Integer i = reserveService.setReserve(reserve);
        RestPOJO restPOJO = new RestPOJO();
        if (i>0){
            restPOJO.setMessage("修改成功");
            restPOJO.setStatus(1000);
        }else {
            restPOJO.setMessage("修改失败");
            restPOJO.setStatus(1001);
        }
        return restPOJO ;
    }
}
